<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">

<head>
    <meta charset="UTF-8">
    <title>我的订单</title>
    <link href="__PUBLIC__/layui/css/layui.css" rel="stylesheet" />
    <link rel="stylesheet" href="__PUBLIC__/css/global.css" media="all">
  <link href="__PUBLIC__/Font-Awesome/css/font-awesome.css" rel="stylesheet" />
    <script src="__PUBLIC__/js/xlsx.full.min.js"></script>
    <script src="/Public/js/laydate/laydate.js"></script>
</head>
<style>
    .site-table{width: 100%;}
    .yourclass  .layui-form-item{margin-bottom:0px;}
    .expless ul{clear: both;}
    .expless ul li{ float: left;}
</style>

<body>
<div class="admin-main">
   <!-- <blockquote class="layui-elem-quote">
        <form  class="layui-form" action="">
            <div class="custom-form-item">
                <label class="layui-form-label">团队订单：</label>
                <div class="layui-input-inline">
                    <select name="orderstatus">
                        <option value="">团队订单状态 </option>&lt;!&ndash;1:正常 2：结束 3：删除 4：抢购中&ndash;&gt;
                        <option value="1" <if condition="$_GET['teamstatus'] eq 1">selected</if>>排队抢购中</option>
                        <option value="2" <if condition="$_GET['teamstatus'] eq 2">selected</if>>结束</option>
                        <option value="3" <if condition="$_GET['teamstatus'] eq 3">selected</if>>删除</option>
                        <option value="4" <if condition="$_GET['teamstatus'] eq 4">selected</if>>抢购中</option>
                    </select>
                </div>
            </div>
            <div class="custom-form-item">
                <label class="layui-form-label">团队名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="teamname" maxlength="20" placeholder="团队名称匹配" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="custom-form-item">
                <button class="layui-btn search" lay-submit lay-filter="search">搜索</button>
            </div>
            <div class="layui-clear"></div>
        </form>
    </blockquote>-->
    <blockquote class="layui-elem-quote">
        <a href="#" class="layui-btn layui-btn-small" id="batchdata">
            <i class="fa fa-shopping-cart" aria-hidden="true"></i> 批量处理操作
        </a>
        <a href="#" class="layui-btn layui-btn-small" id="pushexcel" data-type="{$type|default=0}">
            <i class="fa fa-file-excel-o" aria-hidden="true"></i> 导出excel
        </a>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>任务列表</legend>
        <div class="layui-field-box">
            <table class=" site-table">
                <thead>
                <tr>
                    <th><input name="sortnum" type="checkbox" id="selected-all">id</th>
                    <th>订单号</th>
                    <th>站点</th>
                    <th style="max-width: 120px;">商品名</th>
                    <th>其他信息</th>
                    <th>商品规格</th>
                    <th>邮箱</th>
                    <th>密码</th>
                    <th>收货手机号</th>
                    <th>订单时间</th>
                    <th>需支付金额</th>
                    <th>订单状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="listcontent" class="layui-form">
                </tbody>
            </table>
        </div>
    </fieldset>
    <div class="admin-table-page">
        <div id="page" class="page">
        </div>
    </div>
</div>
<script id="demo" type="text/html">
    <tr>
        <td><input name="sortnum" type="checkbox" lay-ignore value="{{d.order_id}}">{{d.k+1 }}</td>
        <td>{{d.thirdorderid }}</td>
        <td>{{d.site_name}}</td>
        <td style="max-width: 120px;text-overflow: ellipsis; overflow: hidden;">{{d.order_name}}</td>
        <td> <a data="{{d.k}}" class="layui-icon api">&#xe60f;</a></td>
        <td>{{# if(d.remark.color != ''){ }}颜色:{{d.remark.color}}
           {{#}else if(d.remark.size != ''){ }}
            尺码:{{d.remark.size}}
            {{#} }}

        </td>
        <td>{{ d.u_eamil }}</td>
        <td>{{ d.u_pwd }}</td>
        <td>{{d.mobile}}</td>
        <td>{{d.ordertime}}</td>
        <td>{{d.order_price}}</td>
        <td>
            {{# if(d.order_type == 2){ }} <span>已付款</span> {{# }else if(d.order_type == 1 && d.m_id==0){ }} <span>待付款</span>{{# }else if(d.order_type == 4){ }} <span>交易关闭</span>{{# }else if(d.order_type == 5){ }} <span>其他问题</span>{{# }else if(d.order_type == 6){ }} <span>超时未支付</span>{{# }else if(d.order_type == 1 && d.m_id==1){ }} <span>已锁定</span>{{# }}}
        </td>
        <td>
            {{# if(d.order_type == 1 && d.m_id == 0){ }}
            <a  data="{{d.order_id}}" class="layui-btn layui-btn-normal layui-btn-mini gopay"><i class="layui-icon"></i>去付款</a>
            {{# }else if(d.order_type == 2){ }}
            <a  data="{{d.order_id}}" class="layui-btn layui-btn-mini getemress">获取快递</a>
            {{#} }}

            {{#if(d.m_id == 0){}}
            <a  data="{{d.order_id}}" class="layui-btn layui-btn-danger layui-btn-mini del"><i class="layui-icon">&#xe640;</i>删除</a>
            {{#} }}


        </td>
    </tr>
</script>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>

<script>
    var form,layer,$;
    layui.config({
        base: '__PUBLIC__/layui/modules/'
    });
    layui.use(['layer','icheck', 'form','laypage','laytpl'], function () {
        var laypage = layui.laypage,laytpl = layui.laytpl;
        form = layui.form();
        $ = layui.jquery
        layer=layui.layer;
        var pagelistdate;
        var curr;
        form.render();
        $('input').iCheck({
            checkboxClass: 'icheckbox_flat-green'
        });
        laypage({
            cont: 'page',
            pages: {$page} //总页数
            ,skip: true
            ,
            groups: 5 //连续显示分页数
            ,

            jump: function(obj, first) {
                curr = obj.curr;
                listcontent.innerHTML='';
                $.ajax({
                    type: "GET",
                    url: "",
                    data: { p:curr},
                    async: false,
                    success: function(date){
                        if(date['code']==101) {
                            pagelistdate =date .data;
                            layui.each(date.data, function (k, v) {
                                v.k=k;
                                var getTpl = demo.innerHTML;
                                laytpl(getTpl).render(v, function (html) {
                                    listcontent.innerHTML += html;
                                });
                            });
                        }
                    }
                });

                caozuo();
                ichecklist();

            }
        });
        //批量处理
        $('#batchdata').on('click', function() {
            var pidvalue = "";
            var i=0;
            $('input[name="sortnum"]:checked').each(function() {
                pidvalue += $(this).val() + ','
                i=1;
            });
            if(i==1){
                layer.msg("功能开发中",{icon: 5});
                var url = "{:U('MyOrder/batch')}";
                layer.confirm('确认任务批量操作吗', {
                    btn: ['删除', '取消'] //可以无限个按钮
                },function(index, layero){
                    $.post(url, {type:1,ids:pidvalue,p:curr}, function(data){
                        if(data.code=="101"){
                            layer.msg(data.msg,{icon: 6, time: 3000},function(){
                                window.location.reload();
                            });

                        }else {
                            // layer.close(index);
                            layer.msg(data.msg,{icon: 5,time: 2000});

                        }
                    })}
                    );
            }else{
                layer.msg("请勾选",{icon: 5});
            }
        });
        $('#pushexcel').on('click',function(){
            $excelurl="{:U('MyOrder/pushexcel')}"
            console.log($(this));
            $type=$(this).attr('data-type');
            $excelurl=$excelurl+'?type='+$type
            $.get($excelurl,function(data){
                if(data.code == '4001'){
                    layer.msg(data.msg,{icon: 5});
                    return;
                }
                layer.open({
                    title:'导出指定商品订单',
                    type: 1,
                    skin: 'layui-layer-rim',
                    area: ['400px','400px'],
                    content: data
                });
            });

        });
        function ichecklist() {
            $('input').iCheck({
                checkboxClass: 'icheckbox_flat-green'
            });
            $('.site-table tbody tr').on('click', function (event) {
                var $this = $(this);
                var $input = $this.children('td').eq(0).find('input');
                $input.on('ifChecked', function (e) {
                    $this.css('background-color', '#EEEEEE');
                });
                $input.on('ifUnchecked', function (e) {
                    $this.removeAttr('style');
                });
                $input.iCheck('toggle');
            }).find('input').each(function () {
                var $this = $(this);
                $this.on('ifChecked', function (e) {
                    $this.parents('tr').css('background-color', '#EEEEEE');
                });
                $this.on('ifUnchecked', function (e) {
                    $this.parents('tr').removeAttr('style');
                });
            });
            $('#selected-all').on('ifChanged', function (event) {
                var $input = $('.site-table tbody tr td').find('input');
                $input.iCheck(event.currentTarget.checked ? 'check' : 'uncheck');
            });
        }

      /*  $('.add').click(function(){
            var url = "{:U('Team/createTeamTask')}";
            $.get(url,function(data){
                if(data.code == '4001'){
                    layer.msg(data.msg,{icon: 5});
                    return;
                }
                layer.open({
                    title:'创建团队任务',
                    type: 1,
                    skin: 'layui-layer-rim',
                    area: ['800px','500px'],
                    content: data
                });
            });
        });*/

        function caozuo(){
            $('.gopay').click(function () {
                var url = "{:U('MyOrder/goPay')}";
                var id = $(this).attr('data');
                _this=$(this);
                    $.post(url, {id: id}, function (data) {
                        if (data.code == '4001') {
                            layer.msg(data.msg,{icon: 6, time: 3000},function(){
                                window.location.reload();
                            });
                            return;
                        } else {
                            layer.confirm('', {
                                title:'支付',
                                skin: 'layer-ext-moon',
                                content: data.data,
                                btn: ['已经扫码','未扫码'],
                                cancel: function(){
                                    $.post(url, {id: id,is_close:1}, function (data) {
                                        window.location.reload();
                                    });
                                }
                            }, function(index, layero) {
                                $.post("{:U('MyOrder/confirmGoPay')}", {id: id}, function (data) {
                                    if(data.code==101) {
                                        _this.remove();
                                        _this.html('<a  data="'+id+'" class="layui-btn layui-btn-mini getemress">获取快递</a>');
                                        layer.closeAll()
                                    }
                                    caozuo();
                                    layer.msg(data.msg, {icon: 6});
                                    return;
                                });

                            },function(index){
                                $.post(url, {id: id,is_close:1}, function (data) {
                                    window.location.reload();
                                });
                            });
                        }

                });
            });
            $('.api').click(function(){
                var id = $(this).attr('data');
                $html='<div class="layui-form-item"><label class="layui-form-label">用户名：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['firstname']+' </div></div>';
                $html+='<div class="layui-form-item"><label class="layui-form-label">用户生日：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['birthday']+'</div></div>';
                $html+='<div class="layui-form-item"><label class="layui-form-label">商品名：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['order_name']+'</div></div>';
                $html+='<div class="layui-form-item"><label class="layui-form-label">商品价格：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['order_price']+'</div></div>';
                $html+='<div class="layui-form-item"><label class="layui-form-label">订单价格：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['goods_countprice']+'</div></div>';
                $html+='<div class="layui-form-item"><label class="layui-form-label">其他信息：</label><div class="layui-input-block" style="padding: 9px 0px;">颜色'+pagelistdate[id]['remark']['color']+"尺码"+pagelistdate[id]['remark']['size']+pagelistdate[id]['remark']['sytle']+'</div></div>';
                $html+='<div class="layui-form-item"><label class="layui-form-label">第三方订单号：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['thirdorderid']+'</div></div>';

                $html+='<div class="layui-form-item"><label class="layui-form-label">支付类型：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['pay_type']+'</div></div>';
                $html+='<div class="layui-form-item"><label class="layui-form-label">省份/区域：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['u_field']['addressremark']['province']+pagelistdate[id]['u_field']['addressremark']['district']+'</div></div>';
                $html+='<div class="layui-form-item"><label class="layui-form-label">定位点：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['u_field']['addressremark']['street']+'</div></div>';
                $html+='<div class="layui-form-item"><label class="layui-form-label">用户地址：</label><div class="layui-input-block" style="padding: 9px 0px;">'+pagelistdate[id]['u_address']+'</div></div>';


                layer.open({
                    type: 1,
                    title: false,
                    area: '516px',
                    closeBtn: 0,
                    shadeClose: true,
                    skin: 'yourclass',
                    content: $html
                });
            })

            $('.getemress').click(function () {
                var id = $(this).attr('data');
                var bb =layer.load(1, {shade: [0.8, '#393D49'], time: 100000})
                var url = "{:U('MyOrder/getExpress')}";
                $.post(url,{keyid:id},function(data){
                    if(data.code == '4001'){
                        layer.close(bb);
                        layer.msg(data.msg,{icon: 5});
                        return;
                    }else {
                        layer.open({
                            title: '快递信息',
                            type: 1,
                            skin: 'layui-layer-rim',
                            area: ['80%', '600px'],
                            content: data.data,
                            success: function(layero, index){
                                layer.close(bb);
                            }
                        });
                    }
                });
            });

            $('.del').click(function () {
                var id = $(this).attr('data');
                var url = "{:U('MyOrder/delorder')}";
                layer.confirm('确定删除吗', {
                    icon: 3,
                    skin: 'layer-ext-moon',
                    btn: ['确认','取消']
                }, function(){
                    $.post(url,{keyid:id},function(data){
                        if(data.code=='4001'){
                            layer.msg(data.msg,{icon: 5});
                        }else{
                            layer.msg(data.msg, {
                                icon: 6,
                                time: 2000
                            }, function(){
                                window.location.reload();
                            });
                        }
                    });
                });
            });
        }
    });
</script>
</body>

</html>